package com.youxuan.controller;

import com.youxuan.pojo.entity.ResponseResult;
import com.youxuan.pojo.vo.GoodsVo;
import com.youxuan.service.CartDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/cartdetail")
@Api(tags = "购物车详情")
public class CartDetailController {

    @Autowired
    private CartDetailService cartDetailService;

    @PostMapping("/changeSelect")
    @ApiOperation("修改购物车商品选中状态")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "gid",value = "商品id",required = true),
            @ApiImplicitParam(name = "uid",value = "用户id",required = true),
            @ApiImplicitParam(name = "isSelect",value = "选中状态",required = true)})
    public ResponseResult changeSelect(Long gid, Long uid,String isSelect) {
        cartDetailService.changeCartGoodsSelect(gid,uid,isSelect);
        return ResponseResult.okResult();
    }

    @PostMapping("/changeNum")
    @ApiOperation("修改购物车商品数量")
    @ApiImplicitParams({@ApiImplicitParam(name = "gid",value = "商品id",required = true),
            @ApiImplicitParam(name = "uid",value = "用户id",required = true),
            @ApiImplicitParam(name = "num",value = "商品数量",required = true)})
    public ResponseResult changeNum(Long gid,Long uid,Integer num) {
        cartDetailService.changeCartGoodsNum(gid,uid,num);
        return ResponseResult.okResult();
    }

    @PostMapping("/detail")
    @ApiOperation("获取购物车商品详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "gid", value = "商品id", required = true),
            @ApiImplicitParam(name = "uid", value = "用户id", required = true)})
    public ResponseResult<GoodsVo> getCartGoodsDetail(Long gid,Long uid) {
        GoodsVo goodsVo = cartDetailService.getCartGoodsDetail(gid, uid);
        return ResponseResult.okResult(goodsVo);
    }

    @PostMapping("/delete")
    @ApiOperation("删除购物车商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gid", value = "商品id", required = true),
            @ApiImplicitParam(name = "uid", value = "用户id", required = true)
    })
    public ResponseResult deleteCartGoods(Long gid,Long uid) {
        cartDetailService.deleteCartGoods(uid,gid);
        return ResponseResult.okResult();
    }




}
